using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TXLooker.WorkItemExtention.Core
{
    public static class WorkItemsGlobal
    {
        public static string GetWorkItemFieldValue( WorkItem item, CoreField fieldType )
        {
            if( object.ReferenceEquals( item, null ) )
                throw new ArgumentException();

            Field field = null;

            try
            {
                field = item.Revisions[item.Revision - 1].Fields[fieldType];
            }
            catch { }

            return field == null ? string.Empty : ( field.Value == null ? string.Empty : field.Value.ToString() );
        }

        public static object GetWorkItemFieldValue( WorkItem item, string fieldName )
        {
            if( object.ReferenceEquals( item, null ) )
                throw new ArgumentException();

            Field field = null;
            try
            {
                FieldCollection fields = item.Revisions[item.Revision - 1].Fields;

                if( fields.Contains(fieldName) )
                    field = fields[fieldName];
            }
            catch { }

            return field == null ? string.Empty : field.Value;
        }
    }
}
